"""
运行环境生成器
使用该脚本生成所有需要的数据库
"""

import csv

# 定义表头
sales_headers = ["ticket_id", "time_table_id", "buyer_id"]
time_table_headers = ["time_table_id", "time_launch", "spot_launch", "spot_arrive",
                      "duration", "ticket_price", "capicity", "ticket_sole_cnt", "is_canceled"]
user_headers = ["user_id", "name", "passwd", "wallet"]

# 编造的列车时间表数据库
time_table_db = [
    ['1', '18:00', 'Nanjing South', 'Yan City',
        '02h30m', '54.5', '30', '0', '0'],
    ['2', '18:30', 'Nanjing South', 'Lanyun Bay',
        '03h30m', '150.0', '25', '0', '0'],
    ['3', '19:00', 'Nanjing South', 'Suqian City',
        '08h30m', '400.0', '30', '0', '0'],
    ['4', '19:30', 'Nanjing South', 'Wuhan City',
        '01h30m', '54.5', '20', '0', '0'],
    ['5', '20:00', 'Nanjing South', 'Hangzhou City',
        '02h30m', '54.5', '20', '0', '0'],
    ['6', '20:30', 'Nanjing South', 'Jangbei Area',
        '02h30m', '54.5', '20', '0', '0'],
    ['7', '21:00', 'Chengdu East', 'Longchang West',
        '02h30m', '54.5', '20', '0', '0'],
    ['8', '21:30', 'Chengdu East', 'Gaoxing Area',
        '02h30m', '54.5', '20', '0', '0'],
    ['9', '22:00', 'Chengdu East', 'Neijiang North',
        '02h30m', '54.5', '20', '0', '0'],
    ['10', '22:30', 'Chengdu East', 'Chongqing South',
        '02h30m', '54.5', '20', '0', '0'],
    ['11', '23:00', 'Chengdu East', 'Longchang North',
        '02h30m', '54.5', '20', '0', '0'],
    ['12', '23:30', 'Beijing', 'Taipei',
        '02h30m', '54.5', '20', '0', '0'],
    ['100', '23:30', 'Caiyun West', 'Xishan East',
        '02h30m', '54.5', '20', '0', '0']
]

# 编造的销售记录数据库
sales_db = [
]

# 编造的用户数据库
user_db = [
    ['zhangsan', '张三', 'zsnb', '1000'],
    ['rice', 'Rice', 'vain', '1000'],
    ['tri', 'Tri', 'told', '1000'],
    ['meng', 'MengYan', 'dsqc', '1000']
]


def write2csv(name, headers, data):
    with open(name, "w", newline="\n") as f:
        writer = csv.writer(f)
        writer.writerow(headers)
        writer.writerows(data)


# 写入三个数据库
write2csv("../db/time_table.csv", time_table_headers, time_table_db)
write2csv("../db/sales.csv", sales_headers, sales_db)
write2csv("../db/user.csv", user_headers, user_db)
